package Server.Game.Questions;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

public class Question implements Serializable{

	private static final long serialVersionUID = 1L;
	private String content;
	private List<Answer> answers;		

	public Question() {
		answers = new ArrayList<Answer>();
	}

	public void setContent(String content) {
		this.content = content;
	}

	public String getContent() {
		return content;
	}

	public void addAnswer(Answer answer) {
		answers.add(answer);
		Collections.shuffle(answers);
	}

	public List<Answer> getAnswers() {
		return answers;
	}

	public boolean wrongOrRightAnswer(String content){
		for (Answer answer : answers) {
			if (content.equalsIgnoreCase(
					answer.getContent())
					&& answer.isRight()) {
				answers.remove(answer);
				return true;
			}
			if (content.equalsIgnoreCase(
					answer.getContent())){
				answers.remove(answer);
				break;
			}
		}
		return false;
	}

	public boolean changeQuestion(){
		boolean containsRightAnswer = false;
		boolean containsWrongAnswer = false;
		for (Answer answer : answers){
			if(answer instanceof  RightAnswer){
				containsRightAnswer = true;
			}else{
				containsWrongAnswer = true;
			}
		}
		if(containsRightAnswer && containsWrongAnswer){
			return false;
		}
		return true;
	}
}